package com.yumei.trader.gym.page;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.yumei.trader.gym.R;
import com.yumei.trader.gym.client.BasePage;
import com.yumei.trader.gym.client.TGApplication;
import com.yumei.trader.gym.dbase.DBaseConst;
import com.yumei.trader.gym.view.GeneralPagerAdapter;


public class PageAppGuide extends BasePage  {

    private TGApplication mApp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mApp = (TGApplication) this.getApplication();

        setContentView(R.layout.page_app_guide);
        transparentBar();
        registerComponent();
    }

    @SuppressLint("SetTextI18n")
    private void registerComponent() {

        ViewPager viewPager = this.findViewById(R.id.guide_viewpager);
        GeneralPagerAdapter adapter = new GeneralPagerAdapter();
        viewPager.setAdapter(adapter);

        View guide01 = inflate(R.layout.page_guide_image);
        ImageView topImage = guide01.findViewById(R.id.guide_top_img);
        topImage.setImageResource(R.mipmap.bg_guide_01_top);
        TextView topText = guide01.findViewById(R.id.guide_top_txt);
        topText.setText(getResources().getString(R.string.guide_01_top));
        ImageView centerImage = guide01.findViewById(R.id.guide_center_img);
        centerImage.setImageResource(R.mipmap.bg_guide_01_center);

        //bottomText.setText(getResources().getString(R.string.guide_01_bottom));
        TextView startText1 = guide01.findViewById(R.id.guide_start);
        startText1.setText("NEXT");
        startText1.setOnClickListener(v -> viewPager.setCurrentItem(1, true));
        adapter.addView(guide01);

        View guide02 = inflate(R.layout.page_guide_image);
        topImage = guide02.findViewById(R.id.guide_top_img);
        topImage.setImageResource(R.mipmap.bg_guide_02_top);
        topText = guide02.findViewById(R.id.guide_top_txt);
        topText.setText(getResources().getString(R.string.guide_02_top));
        centerImage = guide02.findViewById(R.id.guide_center_img);
        centerImage.setImageResource(R.mipmap.bg_guide_02_center);
        // bottomText.setText(getResources().getString(R.string.guide_02_bottom));
        TextView startText2 = guide02.findViewById(R.id.guide_start);
        startText2.setText("NEXT");
        startText2.setOnClickListener(v -> viewPager.setCurrentItem(2, true));
        adapter.addView(guide02);

        View guide03 = inflate(R.layout.page_guide_image);
        topImage = guide03.findViewById(R.id.guide_top_img);
        topImage.setImageResource(R.mipmap.bg_guide_03_top);
        topText = guide03.findViewById(R.id.guide_top_txt);
        topText.setText(getResources().getString(R.string.guide_03_top));
        centerImage = guide03.findViewById(R.id.guide_center_img);
        centerImage.setImageResource(R.mipmap.bg_guide_03_center);
        // bottomText.setText(getResources().getString(R.string.guide_03_bottom));
        TextView startText3 = guide03.findViewById(R.id.guide_start);
        startText3.setText("START");
        startText3.setOnClickListener(v -> {
            mApp.getDBMrg().addParam(DBaseConst.Is_First_Start, "false");
            mApp.getDBMrg().save();
            showHomeScreen();
        });
        adapter.addView(guide03);
    }

    /**
     * 主界面
     */
    private void showHomeScreen(){
        startActivity(PageAppHome.class);
        this.finish();
    }

}
